<template>
  <div class="login">
    <Header title="设置新密码"></Header>
    <div class="login-main">
      <Field v-model="password" type="password" showPassword placeholder="请输入密码" />
      <Field v-model="confirmPassword" type="password" showPassword placeholder="请再次输入密码" />
      <Button @click="submit" class="login-btn" type="primary" block round>登录</Button>
    </div>
  </div>
</template>
<script>
import Header from "../components/Header.vue";
import Field from "../components/Field.vue";
import Button from "../components/Button.vue";
import Divider from "../components/Divider.vue";
import { isEmpty } from "lodash";

//  鉴权
export default {
  components: {
    Header,
    Field,
    Button,
    Divider
  },
  data() {
    return {
      password: "",
      confirmPassword: ""
    };
  },
  methods: {
    _vaildate() {
      if (isEmpty(this.password)) {
        return "密码不能为空";
      }
      if (isEmpty(this.confirmPassword)) {
        return "确认密码不能为空";
      }
      if (this.password!==this.confirmPassword){
        return '密码不一致';
      }
    },
    submit(){
      const err = this._vaildate()
      if (err) {
        return alert(err);
      }
      const {phone, code} = this.$route.query;
      this.$service.resetPasswordNotLogin({
        password: this.password,
        phone,
        vailCode: code
      }).then(data=>{
        alert('重置密码成功');
        this.$router.push('/login');
        // if (data.success)
      })
    }
  }
};
</script>

